package com.dl.utils;

import org.junit.Test;

import java.util.Random;

/**
 * @author DL
 * @create 2021-05-25 18:26
 */
public class SaltUtils {

    /**
     * 生成salt
     * @param n
     * @return
     */
    public static String getSalt(int n){
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()".toCharArray();

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n ; i++){
            char aChar = chars[new Random().nextInt(chars.length)];
            sb.append(aChar);
        }
        return sb.toString();
    }

    @Test
    public void test(){
        System.out.println("getSalt(5) = " + getSalt(10));
    }
}
